#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 20 18:46:16 2018

@author: Alexandre Dauphin

This script plots the Figures S4 and S5 of the supplementary material of the paper.
"""

import numpy as np
from matplotlib import pyplot as plt

#### Loading the data ####

name='ssh_phase_diagram_1000.npz'
aa=np.load(name)



vecdis=aa['vecdis']
vecm=aa['vecj1']

matmcd=aa['matmcd']
matwind=aa['matwind']
matgx=aa['matgx']

varmcd=aa['varmcd']
varwind=aa['varwind']
vargx=aa['vargx']

vecw_bound=aa['vecw_bound']
vecm_bound=aa['vecj1_bound']
kdis=aa['kdis']

#### Computation of the error bars ####

stdmcd=varmcd-matmcd**2
stdmcd[np.abs(stdmcd)<1E-8]=0.
stdmcd=np.sqrt(stdmcd)/np.sqrt(kdis)

stdgx=vargx-matgx**2
stdgx[np.abs(stdgx)<1E-8]=0.
stdgx=np.sqrt(stdgx)/np.sqrt(kdis)

vecw_bound[0]=0

vw=np.array([0,6])
vm=np.array([0.1,0.1])


#### Plot of the Figure S5(a) ####

x,y= np.meshgrid(vecdis,vecm)
plt.figure()
plt.pcolormesh(x,y,np.transpose(matwind),vmin=-0.05,vmax=1.05)
plt.plot(vecw_bound,vecm_bound,'r-',linewidth=4)
plt.ylim(0.,2.)
plt.colorbar()
plt.title('Figure S5(a), ' +r'$\nu$')
plt.xlabel('W')
plt.ylabel('m')
plt.savefig('fig_S5a.png',dpi=300)

#### Plot of the Figure S5(b) ####

plt.figure()
plt.pcolormesh(x,y,np.transpose(matmcd),vmin=-0.05,vmax=1.05)
plt.plot(vecw_bound,vecm_bound,'r-',linewidth=4)
plt.ylim(0.,2.)
plt.colorbar()
plt.title('Figure S5(b), ' +r'$\langle\bar{\mathcal{C}}\rangle$')
plt.xlabel('W')
plt.ylabel('m')
plt.savefig('fig_S5b.png',dpi=300)

#### Plot of the Figure S5(c) ####

plt.figure()
plt.pcolormesh(x,y,np.transpose(matgx),vmin=-0.05,vmax=1.05)
plt.plot(vecw_bound,vecm_bound,'r-',linewidth=4)
plt.ylim(0.,2.)
plt.colorbar()
plt.title('Figure S5(c), ' +r'$\langle\bar{\mathcal{C}}\rangle_\infty$')
plt.xlabel('W')
plt.ylabel('m')
plt.savefig('fig_S5c.png',dpi=300)

#### Plot of the Figure S6(a) ####

color_cycle = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']


plt.figure()
liste=[0,7,20]
k=0
for i in liste:
    plt.plot(vecm,matgx[i,:],'o',color=color_cycle[k],markerfacecolor='None')
    plt.errorbar(vecm,matmcd[i,:],yerr=stdmcd[i,:],fmt='.-',color=color_cycle[k])
    plt.plot(vecm,matwind[i,:],'d',color=color_cycle[k])
    k=k+1
    
plt.xlabel('m')
plt.title('Figure S6(a)')

plt.savefig('fig_S6a.pdf')

#### Plot of the Figure S6(b) ####

plt.figure()
liste=[2,18,22]
k=0
for i in liste:
    plt.plot(vecdis,matgx[:,i],'o',color=color_cycle[k],markerfacecolor='None')
    plt.errorbar(vecdis,matmcd[:,i],yerr=stdmcd[:,i],fmt='.-',color=color_cycle[k])
    plt.plot(vecdis,matwind[:,i],'d',color=color_cycle[k])
    k=k+1

plt.title('Figure S6(b)')
plt.xlabel('W')

plt.savefig('fig_S6b.pdf')